package chai.ningning.address;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

public class InetAddressTest1 {

    public static void main(String[] args) throws UnknownHostException {

        //getLocalHost()获取主机 名称 和 IP地址
        InetAddress localhost = InetAddress.getLocalHost();
        System.out.println( localhost );

        //getHostName() 获取主机 名称
        String hostName = localhost.getHostName();
        System.out.println(hostName);

        //getHostAddress() 获取 IP地址 ——以String形式返回一个IP地址
        String hostAddress = localhost.getHostAddress();
        System.out.println(hostAddress);

        //getAddress() 获取 IP地址 —— 以 byte 数组形式返回IP地址
        byte[] address = localhost.getAddress();
        System.out.println(Arrays.toString(address));
    }
}
